// pages/room/room.js
Page({
  data: {
    roomInfo: {
      hostAvatar: './image/avator.webp', // 替换为实际的默认头像路径
      roomName: '示例房间',
      hostName: '房主名字',
      roomId: 'R12345',
      currentMembers: 1,
      maxMembers: 10,
      createTime: '2023-05-20 15:30'
    }
  },
  setCurrentTime: function() {
    const now = new Date();
    const timeString = now.toLocaleTimeString('zh-CN', { hour12: false });
    this.setData({
      currentTime: timeString
    });
  },
  onLoad: function(options) {
    // 如果有传入的 roomId，可以在这里获取房间信息
    if (options.roomId) {
      this.getRoomInfo(options.roomId);
    }
  },

  getRoomInfo: function(roomId) {
    // 这里应该是一个网络请求，获取房间信息
    // 为了演示，我们使用 setTimeout 模拟网络请求
    setTimeout(() => {
      this.setData({
        roomInfo: {
          hostAvatar: '/path/to/host/avatar.png',
          roomName: '欢乐房间',
          hostName: 'John Doe',
          roomId: roomId,
          currentMembers: 3,
          maxMembers: 10,
          createTime: '2023-05-20 16:00'
        }
      });
    }, 1000);
  },

  joinRoom: function() {
    // 这里应该是加入房间的逻辑
    wx.showLoading({
      title: '正在加入房间...',
    });

    // 模拟加入房间的网络请求
    setTimeout(() => {
      wx.hideLoading();
      wx.showToast({
        title: '成功加入房间',
        icon: 'success',
        duration: 2000
      });
      // 这里可以跳转到房间内部页面
      // wx.navigateTo({
      //   url: `/pages/roomInterior/roomInterior?roomId=${this.data.roomInfo.roomId}`
      // });
    }, 2000);
  }
})